<?php
class JsonUtil {
    public static function beginObject($objectName){
        return '{"'. $objectName . '":{';
    }

    public static function endObject(){
        return '}}';
    }

    public static function value($name, $value){
        return '"' . $name . '":"' . $value .'",';
    }

    public static function valueEscaped($name, $value){
        return '"' . $name . '":"' . String::jsonClean($value) .'",';
    }

    public static function valueWithoutTrailingComma($name, $value){
        return '"' . $name . '":"' . $value .'"';
    }

    public static function valueWithoutTrailingCommaEscaped($name, $value){
        return '"' . $name . '":"' . String::jsonClean($value) .'"';
    }

    public static function collection ($name, $arraySubstring){
        return '"' . $name . '":[' . $arraySubstring . ']';
    }

    public static function fullObject($objectName, $values){
        return self::beginObject($objectName) .
        $values . self::endObject();
    }

    function returnJson($object) {
        header('Content-type: application/json');
        echo "/*-secure-\n".json_encode($object)."\n*/";
    }
}
?>
